<template>
	<view class="content">
		<view class="header">
			<view class="tabs">
				<uv-tabs :list="tabsList" :current="current" lineColor="#1DB481" :inactiveStyle="{color:'#333333'}"
					:activeStyle="{color:'#333333'}" @click="tabsClick" :scrollable="false"></uv-tabs>
			</view>
			<view class="info">
				<view class="time font28" @click="Open">
					<view class="title">
						{{current == 0?`${dayTime}`:`${monthTime}`}}
					</view>
					<view class="icon">
						<image src="https://wx.caobenjiankang.com/image/shopowner/close.png" mode="aspectFit"></image>
					</view>
				</view>
				<view class="ring">
					<lchart :rotate="(Number(modelVale.sign_in_list.length)/ Number(modelVale.total_sign_in)).toFixed(2) * 100"
						:diameter="30" color="#1EB481" ringtrackcolor="#ffffff" size="150"></lchart>
					<view class="ringBox">
						<view class="title font24">
							打卡人数/应到人数
						</view>
						<view class="number font42">
							{{modelVale.sign_in_list.length || 0}}/{{modelVale.total_sign_in || 0}}
						</view>
						<view class="btn font24">
							<view class="text">
								打卡明细
							</view>
							<view class="icon">
								<image src="https://wx.caobenjiankang.com/image/shopowner/ri.png" mode="aspectFit"></image>
							</view>
						</view>
					</view>
				</view>
				<view class="rouder">
					<view class="item">
						<view class="data font40">
							{{modelVale.un_sign_in_num || 0}}
						</view>
						<view class="title font24">
							未打卡
						</view>
					</view>
					<view class="item">
						<view class="data font40">
							{{modelVale.chidao_num || 0}}
						</view>
						<view class="title font24">
							迟到
						</view>
					</view>
					<view class="item">
						<view class="data font40">
							{{modelVale.zaotui_num || 0}}
						</view>
						<view class="title font24">
							早退
						</view>
					</view>
					<view class="item">
						<view class="data font40">
							{{modelVale.qingjia_num || 0}}
						</view>
						<view class="title font24">
							请假
						</view>
					</view>
					<view class="item">
						<view class="data font40">
							{{modelVale.jiaban_num|| 0}}
						</view>
						<view class="title font24">
							加班
						</view>
					</view>

				</view>
			</view>
		</view>
		<view class="box">
			<view class="stick">
				<view class="info_tabs">
					<view class="item font30" :class="desIndex == index?'xuan':''" v-for="(item,index) in desList" :key="index"
						@click="qiehuan(index)">
						{{item.name}}({{item.value}})
					</view>
				</view>
				<view class="label" v-if="desIndex == 1">
					<scroll-view class="scroll-view_H" scroll-x="true">
						<view class="item font26">
							缺卡({{modelVale.un_sign_in_list.length}})
						</view>
					</scroll-view>
				</view>
			</view>
			<!-- <view class="item" v-for="(item,index) in modelVale.sign_in_list" :key="index" v-if="desIndex == 0">
				<view class="image">
					<image :src="item.image" mode="aspectFit"></image>
				</view>
				<view class="left">
					<view class="info">
						<view class="title font30">
							{{item.name}}
						</view>
						<view class="time font28">
							{{item.time}}
						</view>
					</view>
					<view class="tips font28">
						{{item.tip}}
					</view>
				</view>
			</view> -->
			<view class="list" v-for="(items,indexs) in modelVale.sign_in_list" :key="indexs" v-if="desIndex == 0">
				<view class="item" v-for="item in items" :key="item.id">
					<view class="image">
						<image :src="item.work_img" mode="aspectFit"></image>
					</view>
					<view class="left">
						<view class="info">
							<view class="title font30">
								{{item.coach_name}}
							</view>
							<view class="time font28">
								{{$u.timeFormat(item.create_time, 'yyyy年mm月dd日 hh:MM')}}
							</view>
						</view>
						<!-- <view class="tips font28">
							缺卡
						</view> -->
					</view>
				</view>
			</view>
			<view class="list" v-for="(items,indexs) in modelVale.un_sign_in_list" :key="indexs" v-if="desIndex == 1">
				<view class="item" v-for="item in items" :key="item.id">
					<view class="image">
						<image :src="item.work_img" mode="aspectFit"></image>
					</view>
					<view class="left">
						<view class="info">
							<view class="title font30">
								{{item.coach_name}}
							</view>
							<view class="time font28">
								{{$u.timeFormat(item.create_time, 'yyyy年mm月dd日 hh:MM')}}
							</view>
						</view>
						<view class="tips font28">
							缺卡
						</view>
					</view>
				</view>
			</view>
		</view>
		<yt-dateTimePicker ref="dayShow" @submit="dayTimes" :start-year="2000" :end-year="2099" :time-init="dayTime"
			:time-hide="[true, true, true, false, false, false]" :time-label="['年', '月', '日']" />
		<yt-dateTimePicker ref="monthShow" @submit="monthTimes" :start-year="2000" :end-year="2099" :time-init="monthTime"
			:time-hide="[true, true, false, false, false, false]" :time-label="['年', '月']" />
	</view>
</template>

<script>
	import lchart from '@/shopowner/components/lj-chart/lj-chart.vue'
	export default {
		components: { lchart },
		data() {
			return {
				tabsList: [{ name: '日统计' }, { name: '月统计' }],
				current: 0,
				modelVale: {
					sign_in_list: []
				},
				dayTime: '',
				month: '',
				monthTime: '',
				desList: [{
						name: '已打卡',
						value: '2'
					},
					{
						name: '应到但未打卡',
						value: '2'
					}
				],
				desIndex: 0,
			};
		},
		onLoad() {
			this.getCurrentTime()
			this.getData()
		},
		methods: {
			async getData() {
				if (this.current == 0) {
					let data = await this.$api.shopowner.coachSignIn({ date: this.dayTime })
					this.modelVale = data
					this.desList[0].value = data.sign_in_list.length
					this.desList[1].value = data.un_sign_in_list.length
				}
				if (this.current == 1) {
					let data = await this.$api.shopowner.coachMonthSignIn({ date: this.dayTime, month: this.month })
					console.log(data, 'data');
				}
			},
			getCurrentTime() {
				const now = new Date();
				const year = now.getFullYear();
				const month = String(now.getMonth() + 1).padStart(2, '0');
				const day = String(now.getDate()).padStart(2, '0');
				const hours = String(now.getHours()).padStart(2, '0');
				const minutes = String(now.getMinutes()).padStart(2, '0');
				const seconds = String(now.getSeconds()).padStart(2, '0');
				this.dayTime = `${year}-${month}-${day}`;
				this.monthTime = `${year}-${month}`;
				this.month = month
			},
			tabsClick(item) {
				this.current = item.index
				this.getData()
			},
			dayTimes(e) {
				this.dayTime = `${e.year}-${e.month}-${e.day}`;
			},
			monthTimes(e) {
				this.monthTime = `${e.year}-${e.month}`;
				this.month = e.month
			},
			Open() {
				if (this.current == 0) {
					this.$refs.dayShow.show();
				}
				if (this.current == 1) {
					this.$refs.monthShow.show();
				}
			},
			dayClose() {
				this.$refs.dayShow.hide();
			},
			monthClose() {
				this.$refs.monthShow.hide();
			},
			qiehuan(index) {
				this.desIndex = index
			}
		}
	}
</script>

<style lang="scss">
	.content {
		.header {
			background-color: #fff;
			margin-bottom: 18rpx;

			.tabs {
				padding-top: 35rpx;
				border-bottom: 2rpx solid #E7E7E7;
			}

			.info {
				padding: 40rpx 50rpx 66rpx 36rpx;
				display: flex;
				flex-direction: column;
				align-items: center;

				.time {
					width: 100%;
					margin-bottom: 40rpx;
					display: flex;
					align-items: center;

					.title {
						color: #1EB481;
					}

					.icon {
						width: 18rpx;
						height: 10rpx;
						display: flex;
						align-items: center;
						margin-left: 10rpx;

						image {
							width: 18rpx;
							height: 10rpx;
						}
					}
				}

				.ring {
					width: 300rpx;
					height: 300rpx;

					position: relative;

					.ringBox {
						position: absolute;
						left: 50%;
						top: 50%;
						transform: translate(-50%, -50%);
						display: flex;
						flex-direction: column;
						align-items: center;
						width: 100%;

						.title {
							color: #75747D;

						}

						.number {
							color: #1EB481;
						}

						.btn {
							display: flex;
							align-items: center;

							.text {
								color: #1EB481;
							}

							.icon {
								width: 11rpx;
								height: 20rpx;
								display: flex;
								align-items: center;
								margin-left: 8rpx;

								image {
									width: 11rpx;
									height: 20rpx;
								}
							}
						}
					}
				}

				.rouder {
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 100%;
					margin-bottom: 50rpx;

					.item {
						background-color: #fff;

						.title {
							color: #666666;
						}

						.data {
							color: #333333;
							text-align: center;
							margin-bottom: 28rpx;
						}
					}
				}
			}
		}

		.box {
			.stick {
				position: sticky;
				top: 0;
				background-color: #fff;

				.info_tabs {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.item {
						padding: 52rpx 0 16rpx 0;
						width: 50%;
						text-align: center;
						border-bottom: 4rpx solid #ffffff;
					}

					.xuan {
						border-bottom: 4rpx solid #1EB481;
						color: #1EB481;
					}
				}

				.label {
					padding: 20rpx 35rpx;

					.scroll-view_H {
						white-space: nowrap;
						width: 100%;

						.item {
							display: inline-block;
							padding: 17rpx 20rpx;
							background: #E6F9EF;
							border-radius: 10rpx;
							margin-left: 24rpx;
						}

						.item:first-child {
							margin-left: unset;
						}
					}
				}
			}

			.list {
				.item {
					display: flex;
					align-items: center;
					background-color: #fff;

					.image {
						width: 90rpx;
						height: 90rpx;
						border-radius: 50%;
						overflow: hidden;
						margin-right: 25rpx;

						image {
							width: 90rpx;
							height: 90rpx;
						}
					}

					.left {
						padding: 24rpx 38rpx 35rpx 0;
						flex: 1;
						justify-content: space-between;
						border-bottom: 2rpx solid #F0F0F0;

						.info {
							line-height: 43rpx;

							.title {
								color: #151514;
							}

							.time {
								color: #999999;
							}
						}

						.tips {
							color: #999999;
						}
					}
				}
			}
		}
	}
</style>